package com.person.swagger.config;/*
 *@Description swagger2 配置类
 *@Author java02
 *@Date 2018/8/6 15:02
 *
*/

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger2Config {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("swagger")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.person.swagger.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("swagger2使用案例")
                .description("swagger2 代码示例")
                .termsOfServiceUrl("http://10.0.194.39:8003/swaggerDemo/swagger-ui.html")
                .contact("wangpeng")
                .version("1.0")
                .build();
    }

    @Bean
    public Docket createTwoRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("swagger2 ")
                .apiInfo(twoApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.person.swagger.controller2"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo twoApiInfo() {
        return new ApiInfoBuilder()
                .title("分组测试")
                .description("swagger2 代码示例")
                .termsOfServiceUrl("http://10.0.194.39:8003/swaggerDemo/swagger-ui.html")
                .contact("wangpeng")
                .version("1.0")
                .build();
    }
}
